package us.x.slowexp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import us.x.slowexp.domain.Express;
import us.x.slowexp.domain.Page;
import us.x.slowexp.service.PageExpressService;

@Controller
public class PageQuery {
	
	@Autowired
	private PageExpressService pageExpressService;
	
	@RequestMapping("/pageQuery.action")
	public String pageQuery(String num, Model model){
		int totalRecords = this.pageExpressService.queryCounts();
		Page page = new Page(Integer.parseInt(num), totalRecords);
		page.setUrl("pageQuery.action");
		List<Express> records = this.pageExpressService.queryExpress(page);
		for(Express e : records){
			System.out.println(e);
		}
		page.setRecords(records);
		model.addAttribute("page", page);
		return "success";
	}
	
	@RequestMapping("/hisPageQuery.action")
	public String hisPageQuery(String num, Model model){
		int totalRecords = this.pageExpressService.queryHisCounts();
		Page page = new Page(Integer.parseInt(num), totalRecords);
		page.setUrl("hisPageQuery.action");
		List<Express> records = this.pageExpressService.queryHisExpress(page);
		for(Express e : records){
			
			System.out.println(e);
		}
		page.setRecords(records);
		model.addAttribute("page", page);
		return "success";
	}
}
